use crate::gen::bindings::{*};
use std::marker::PhantomData;
use std::os::raw::c_void;
use std::slice;
use std::str;

pub mod gen;

pub struct LLVMString<'a> {
    inner: RustStringRef,
    phantom: PhantomData<&'a str>
}

impl <'a>LLVMString<'a> {
    pub fn new(s: &'a str) -> Self {
        LLVMString {
            inner: RustStringRef {
                s: s.as_ptr() as *mut c_void,
                length: s.len() as size_t
            },
            phantom: PhantomData
        }
    }

    pub fn get_ref(&self) -> RustStringRef {
        self.inner
    }
}

extern "C" fn rust_print(s: RustStringRef) {
    //println!("{}", s.into_string())
}


impl RustStringRef {
    pub fn as_str(&self) -> &str {
        unsafe {
            let t = slice::from_raw_parts(self.s as *mut u8, self.length as usize);
            str::from_utf8(t).expect("not utf8")
        }
    }
}




